package com.aceitunaproject.mapdisplay.config;

import java.security.InvalidParameterException;
import java.util.Properties;



/**
 * Default DisplayConfiguration implementation (Hardcoded Values)
 * 
 * Implemented as singleton, all DisplayConfiguration Implementations should be singletons too.
 * @author Federico Bergstein
 */
public class DefaultDisplayConfiguration implements DisplayConfiguration {

	public static final String SCALING_FACTOR_KEY = "display.scaling.factor";
	public static final String TILE_HEIGHT_KEY = "display.tile.height";
	public static final String TILE_WIDTH_KEY = "display.tile.width";
	public static final String IMAGE_EXTENSION_KEY = "image.extension";
	public static final String IMAGE_FOLDER_KEY = "image.folder";
	public static final String THING_HEIGHT_KEY = "display.thing.height";
	public static final String THING_WIDTH_KEY = "display.thing.width";
	public static final String THING_OFFSET_KEY = "display.thing.offset";

	private static DefaultDisplayConfiguration instance;

	private int scalingFactor;
	private int tileHeight;
	private int tileWidth;
	private String imageExtension;
	private String imageFolder;
	private int thingHeight;
	private int thingWidth;
	private int thingOffset; 

	/**
	 * Private constructor to make it a singleton.
	 */
	private DefaultDisplayConfiguration(Properties props)
	{
		loadProperties(props);
	}
	
	public void loadProperties(Properties props) {
		scalingFactor = Integer.valueOf(props.getProperty(SCALING_FACTOR_KEY, "1"));
		tileHeight = Integer.valueOf(props.getProperty(TILE_HEIGHT_KEY, "64"));
		tileWidth = Integer.valueOf(props.getProperty(TILE_WIDTH_KEY, "128"));
		imageExtension = props.getProperty(IMAGE_EXTENSION_KEY, "png");
		imageFolder = props.getProperty(IMAGE_FOLDER_KEY, "images");
		thingHeight = Integer.valueOf(props.getProperty(THING_HEIGHT_KEY, "33"));
		thingWidth = Integer.valueOf(props.getProperty(THING_WIDTH_KEY, "64"));
		thingOffset = Integer.valueOf(props.getProperty(THING_OFFSET_KEY, "20"));
	}

	/**
	 *  Returns an instance of DefaultDisplayConfiguration
	 */
	public static DefaultDisplayConfiguration getInstance(Properties props)
	{
		if (props == null)
			throw new InvalidParameterException("Properties must not be null.");
		
		if(instance == null)
		{
		   instance = new DefaultDisplayConfiguration(props);
		}
		
		return instance;
	}


	public int getScalingFactor() {
		
		return scalingFactor;
	}

	public int getTileHeight() {

		return tileHeight;
	}


	public int getTileWidth() {

		return tileWidth;
	}


	public String getImageExt() {
		
		return imageExtension;
	}


	public String getImageFolder() {

		return imageFolder;
	}


	public int getThingHeight() {
	
		return thingHeight;
	}


	public int getThingWidth() {
		
		return thingWidth;
	}


	public int getThingOffSet() {

		return thingOffset; 
	}
}
